<?php

namespace app\admin\controller;

use think\Controller;
use think\Request;
use app\model\config as ConfigModel;

/**
 * 后台参数控制器
 *
 * @author Administrator
 */
class Config extends Controller {

    public function __construct() {
        parent::__construct();
        $left = controller("index");
        $left->left();
    }

    public function backconfig(Request $request) {


        $title = "后台参数设置";
        $list = ConfigModel::get(1)->toArray();
        //var_dump($list);
        $this->assign("title", $title);
        $this->assign("list", $list);
        session("cue", "后台参数设置");
        return $this->fetch();
    }

    public function updateconfig() {

        $file = request()->file("logo");
        $data = input("post.");
        $rule = [
            'name|网站后台名称' => 'require',
        ];
        $message = [
            'name.require' => '请填写后台名称！',
        ];

        $res = $this->validate($data, $rule, $message);

        if (true !== $res) {

            return ["status" => -1, 'message' => $res];
        }
        if ($file) {
            $info = $file->move(ROOT_PATH . 'public' . DS . 'static' . DS . 'config');
            if ($info) {

                $data['logo'] = $info->getSaveName();
            }
        }

        if (ConfigModel::update($data, ['id' => 1], true)) {
            return ["status" => 1, 'message' => "保存成功！"];
        } else {
            return ["status" => 2, 'message' => "保存失败！"];
        }
    }

}
